﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Performing_Conversions
{
    class Program
    {
        static void Main(string[] args)
        {
            Int16 i16 = 1;
            Int32 i32 = 1;
            double db = 1;
        }

        struct TypeA
        {
            public int value;

            /// <summary>
            /// Implementing this method allows us to use the = implicit operator to make a int value type passes it's value to the typeA struct
            /// </summary>
            /// <param name="arg"></param>
            /// <returns></returns>
            public static implicit operator TypeA(int arg){
                TypeA res = new TypeA();
                res = arg;
                return res;
            }

            /// <summary>
            /// Implementing this method allows us to return the desired type.value to a int variable value type. In c#, this requires the narrowing conversion
            /// </summary>
            /// <param name="arg"></param>
            /// <returns></returns>
            public static explicit operator int(TypeA arg){
                return arg.value;
            }

            /// <summary>
            /// Implemeting this method allows passing the result we want without boxing the type.value with the string type, and actually a consuming application
            /// of this assembly would use the toString() method without getting the value from it, it would just get it's type's name.
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {
                return this.value.ToString();
            }

        }

    }
}
